package Chapter05;

import java.awt.*;

/**
 * 静态内部类可以使用外部类定义的静态域,但
 * 不能使用非静态域
 * Created by a on 2017/6/11.
 */
public class Test118 {
    public static void main(String[] args) {
        System.out.println("自定义普通车辆:");
        Car car = new Car();
        car.setName("Adui");
        car.setSpeed(60);
        System.out.println(car);
        System.out.println("自定义GPS汽车:");
        GPSCar gpsCar = new GPSCar();
        gpsCar.setName("Audi");
        gpsCar.setSpeed(60);
        System.out.println(gpsCar);
    }
}

class Car {
    private String name;
    private double speed;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("车名:"+name+",");
        sb.append("速度:"+speed+"千米/小时");
        return sb.toString();
    }
}

interface GPS{
    Point getLocation();
}

class GPSCar extends Car implements GPS {
    @Override
    public Point getLocation() {
        Point point = new Point();
        point.setLocation(super.getSpeed(),super.getSpeed());
        return point;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(super.toString());
        sb.append(",坐标:("+getLocation().x+","+getLocation().y+"y");
        return sb.toString();
    }
}

